﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace Kortex.WallManagerControl.FIle_Show
{
    public partial class FileShow : Form
    {
        public FileShow()
        {
            InitializeComponent();
        }

        public FileShow(string title,string fileName)
        {
            InitializeComponent();

            this.Text = title;

            show_result(fileName);
        }


        private byte[] ReadFileIps(string file)
        {
            FileStream inStream = null;
            try
            {
                inStream = File.OpenRead(file);
            }
            catch (FileNotFoundException)
            {
                MessageBox.Show("File not found");
                return null;
            }
            catch (FileLoadException)
            {
                MessageBox.Show("File Load Exception");

                return null;
            }
            catch (DirectoryNotFoundException)
            {

                MessageBox.Show("Directory Not found");
                return null;

            }
            catch (FieldAccessException)
            {

                MessageBox.Show("FieldAccessException");
                return null;

            }
            catch (IOException er)
            {
                MessageBox.Show(er.Message);

                return null;

            }
            int count = 0;
            byte[] Buff = new Byte[inStream.Length];
            count = inStream.Read(Buff, 0, (Int32)inStream.Length);
            inStream.Close();
            //string sJSON = System.Text.ASCIIEncoding.ASCII.GetString(Buff);

            return Buff;

        }
        private void show_result(string fileName)
        {
            byte[] data = ReadFileIps(fileName);
            if (data == null) return;
            string AllIps = System.Text.ASCIIEncoding.ASCII.GetString(data);
            Result_richBox.Clear();

            Result_richBox.Text = AllIps;

        
        }



    }
}
